package ar.com.personalTravellers.generators;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;

import ar.com.personalTravellers.beans.Hotel;
import ar.com.personalTravellers.generators.util.ResourcesDataGeneratorsUtil;
import ar.com.personalTravellers.rowProcessors.HotelContactsRowProcessorCommand;

import com.angel.architecture.flex.locator.ObjectLocator;
import com.angel.common.helpers.FileHelper;
import com.angel.dao.generic.interfaces.GenericDAO;
import com.angel.data.generator.exceptions.DataGeneratorException;
import com.angel.data.generator.interfaces.DataGenerator;
import com.angel.data.generator.interfaces.impl.ImportFileDataGenerator;
import com.angel.io.descriptor.FileProcessorDescriptor;
import com.angel.io.processors.commands.impl.ExcelFileProcessorCommand;
import com.angel.io.processors.runners.imports.impl.ImportFileProcessorRunner;
import com.angel.io.separator.ColumnSeparator;

/**
 *
 * @author William
 */
public class HotelContactsFileDataGenerator extends ImportFileDataGenerator{

    private static final long serialVersionUID = 456392726459660147L;

	@SuppressWarnings("unchecked")
	public Class<? extends DataGenerator>[] getDependecesGenerators() {
        return (Class<? extends DataGenerator>[]) new Class[]
                {
                        CountryFileDataGenerator.class,
                        HotelFileDataGenerator.class
                };
    }

    public ImportFileProcessorRunner prepareImportFileProcessorRunner() {
		FileProcessorDescriptor descriptor = new FileProcessorDescriptor("Hotel Contacts File", ColumnSeparator.COMMA);
		ImportFileProcessorRunner runner = new ImportFileProcessorRunner(descriptor,new ExcelFileProcessorCommand(), new HotelContactsRowProcessorCommand());
        runner.addAliasFor(HotelContactsRowProcessorCommand.HOTEL_NAME_COLUMN,"Nombre Hotel");
        runner.addAliasFor(HotelContactsRowProcessorCommand.CONTACT_NAME_COLUMN,"Nombre Contacto");
        runner.addAliasFor(HotelContactsRowProcessorCommand.CONTACT_SURNAME_COLUMN,"Apellido Contacto");
        runner.addAliasFor(HotelContactsRowProcessorCommand.CONTACT_EMAIL_COLUMN,"Email");
        runner.addAliasFor(HotelContactsRowProcessorCommand.CONTACT_TELEPHONE_COLUMN,"Telefono");
        runner.addAliasFor(HotelContactsRowProcessorCommand.CONTACT_COMMENT_COLUMN,"Comentarios");
        runner.addAliasFor(HotelContactsRowProcessorCommand.CONTACT_COUNTRY_COLUMN,"Pais");
        runner.addParameter(HotelContactsRowProcessorCommand.DAO_FACTORY_PARAMETER_SERVICE_NAME, ObjectLocator.getBeanByName("ptDAOFactory"));
        return runner;
    }

    public InputStream prepareInputStream() {
        try {
            return FileHelper.findInputStreamInClasspath(ResourcesDataGeneratorsUtil.CONTACTS_XLS_RESOURCE);
        } catch (FileNotFoundException e) {
            throw new DataGeneratorException("File not found [" + ResourcesDataGeneratorsUtil.CONTACTS_XLS_RESOURCE + "].", e);
        }
    }

    public Class<? extends Object> getDataGeneratorClass() {
        return Hotel.class;
    }

    @SuppressWarnings("unchecked")
	public GenericDAO<Object, Serializable> getGenericDAO() {
        return (GenericDAO<Object, Serializable>) ObjectLocator.getBeanByName("hotelDAO");
    }
}